from django.shortcuts import render, get_object_or_404
from .models import Author, Book
from django.contrib.admin.views.decorators import staff_member_required

def author_list(request):
    authors = Author.objects.all()
    return render(request, 'books/author_list.html', {'authors': authors})

def author_detail(request, author_id):
    author = get_object_or_404(Author, pk=author_id)
    return render(request, 'books/author_detail.html', {'author': author})

@staff_member_required
def librarian_borrowed_books(request):
    borrowed_books = Book.objects.exclude(borrowed_by__isnull=True)
    return render(request, 'books/librarian_borrowed_books.html', {'borrowed_books': borrowed_books}) 